<?php
/**
 * 未支付订单提醒
 */
class Remind_UnpaidOrders 
{
	public function run ()
	{
		$order_mobile = new Report_Order_Mobile;
		$mobiles      = $order_mobile->unpaid_orders();
		$message      = kohana::config('remind.message.unpaid_orders');

		if (count($mobiles) > Kohana::config('remind.limit.unpaid_orders.mobiles'))
		{
			Kohana::$log->add(Log::ERROR, "REMIND: unpaid_orders got ".count($mobiles)." mobiles, refused");
			return FALSE;
		}

		$sms = notice::factory('sms')->message($message);
		foreach ($mobiles as $number => $uid)
		{
			$sms->to($number)->send();
			Kohana::$log->add(Log::DEBUG, '[remind][unorder]'.$number);

			events::notify(Kohana::config('events.system.notice'), array(
						'uid'    => $uid,
						'action' => 'remind_order_pay',
						'value'  => $number.'',
						'comment'=> '短信提醒: 订单支付提醒',
						'time'   => time(),
						));
		}
	}
}
